<template>
  <el-header>
    <div class="left">
      <el-icon @click="handelCollapsed" class="collapsed-icon">
        <Menu :size="30" />
      </el-icon>
      <span>企业门户网站管理系统</span>
    </div>
    <div class="right">
      <div>欢迎 {{ $store.state.userInfo.username }} 回来</div>
      <el-dropdown trigger="hover">
        <el-icon class="el-icon--right">
          <User :size="30" color="white" />
        </el-icon>
        <template #dropdown>
          <el-dropdown-menu>
            <!-- divided -->
            <el-dropdown-item @click="handerCenter">个人中心</el-dropdown-item>
            <el-dropdown-item @click="handerLogout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script setup>
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { Menu, User } from "@element-plus/icons-vue";
const store = useStore();
const router = useRouter();

const handelCollapsed = () => {
  store.commit("changeCollapse");
  console.log(store.state.isCollapsed);
};

const handerCenter = () => {
  router.push("/center");
};

const handerLogout = () => {
  localStorage.removeItem("token");
  store.commit("clearUserInfo");
  router.push("/login");
};
</script>

<style lang="scss" scoped>
.el-header {
  background-color: #2d3a4b;
  color: white;
  width: 100%;
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.left,
.right {
  display: flex;
}
.left {
  align-items: center;
  gap: 10px;

  .collapsed-icon {
    margin-top: 2px;
    cursor: pointer;
  }
}
.right {
  .el-dropdown {
    .el-icon--right {
      font-size: 18px;
      font-weight: bold;
      margin-left: 10px;
      cursor: pointer;
      display: flex;
      align-items: center;

      &:focus-visible {
        outline: unset !important;
      }
    }
  }
}
</style>